#include <iostream>
#include <vector>
#include <map>
using namespace std;

int fourSumCountSlef(vector<int> &nums1, vector<int> &nums2, vector<int> &nums3, vector<int> &nums4)
{
    unordered_map<int, int> TwoSum;
    int len = nums1.size();
    int cnt = 0;
    for (int i = 0; i < len; i++)
        for (int j = 0; j < len; j++)
        {
            if (TwoSum.find(nums1[i] + nums2[j]) == TwoSum.end())
            {
                TwoSum[nums1[i] + nums2[j]] = 1;
            }
            else
                TwoSum[nums1[i] + nums2[j]]++;
        }
    for (int i = 0; i < len; i++)
        for (int j = 0; j < len; j++)
        {
            if (TwoSum.find(-(nums3[i] + nums4[j])) != TwoSum.end())
                cnt += TwoSum[-(nums3[i] + nums4[j])];
            //! 注意这里，cnt不能只是简单的++，因为Twosum中与nums3+nums4相加为0的组合可能不止一个，而是有value个
            //! 所以要将这个value加入到cnt中
        }
    return cnt;
}

int fourSumCount(vector<int> &nums1, vector<int> &nums2, vector<int> &nums3, vector<int> &nums4)
{
    unordered_map<int, int> countAB;
    for (auto &u : nums1)
    {
        for (auto &v : nums2)
        {
            ++countAB[u + v];
        }
    }
    int ans = 0;
    for (auto &u : nums3)
    {
        for (auto &v : nums4)
        {
            if (countAB.count(0 - u - v))
            {
                ans += countAB[0 - u - v];
            }
        }
    }
    return ans;